package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.system.model.CommonUser;
import com.eling.elcms.travel.model.CheckInImplement.PaymentMethod;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * 入住联盟结算
 * @author zhoulin
 *
 */
@Entity
@Table(name = "travel_alliancesettlement")
@Indexed
public class AllianceSettlement extends BaseModel{

	private static final long serialVersionUID = 7261025533205206190L;
	
	@Id
	@In
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkAllianceSettlement;
	
	/** 入住确认 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkAllianceConfirm")
	@IndexedEmbedded(depth = 1)
	private AllianceConfirm allianceConfirm;
	
	/** 经办人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOperator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;
	
	/** 结算日期 */
	@Column
	@Field
	@Between
	private Date settlementDate;
	
	/** 结算方式 */
	@ElementCollection(fetch = FetchType.EAGER)
	@Enumerated(EnumType.STRING)
	@CollectionTable(name = "travel_alliance_paymentmethods", joinColumns = @JoinColumn(name = "pkAllianceSettlement"))
	@Column(name = "paymentMethods", nullable = false)
	private Set<PaymentMethod> paymentMethods;
	
	/** 实收金额合计 */
    @Column
	private Double balance;
	
	/** 结算合计备注 */
    @Column
	private String description;	
    
    /** 状态 */
   	@Enumerated(EnumType.STRING)
   	@Field
   	@In
   	@FieldBridge(impl = EnumBridge.class)
   	private ConfirmStatus confirmStatus;
   	
   	@JsonSerialize(using = EnumSerializer.class)
   	public static enum ConfirmStatus {
   		NoConfirm("待确认"),Confirm("已确认");

   		private String display;
   		ConfirmStatus(String display) {
   			this.display = display;
   		}
   		public String getDisplay() {
   			return display;
   		}
   	}

   	/** 确认日期 */
   	@Column
   	@Field
   	@Between
   	private Date confirmDate;
   	
   	/** 款项内容 */
   	@Column
   	private String content;
   	
   	/** 是否开票 */
   	@Column
   	private Boolean isInvoice;
   	
   	/** 开票日期 */
   	@Column
   	@Field
   	@Between
   	private Date invoiceDate;
   	
   	/** 收款单位 */
   	@Column
   	private String payee;
   	
   	/** 付款单位 */
   	@Column
   	private String payer;
   	
   	/** 确认人 */
   	@ManyToOne(fetch = FetchType.LAZY)
   	@JoinColumn(name = "pkUser")
   	@IndexedEmbedded(depth = 1)
   	private CommonUser confirmUser;
	
	@Version
	private Integer version;
	
	public Long getPkAllianceSettlement() {
		return pkAllianceSettlement;
	}

	public void setPkAllianceSettlement(Long pkAllianceSettlement) {
		this.pkAllianceSettlement = pkAllianceSettlement;
	}

	public AllianceConfirm getAllianceConfirm() {
		return allianceConfirm;
	}

	public void setAllianceConfirm(AllianceConfirm allianceConfirm) {
		this.allianceConfirm = allianceConfirm;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public Date getSettlementDate() {
		return settlementDate;
	}

	public void setSettlementDate(Date settlementDate) {
		this.settlementDate = settlementDate;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Set<PaymentMethod> getPaymentMethods() {
		return paymentMethods;
	}

	public void setPaymentMethods(Set<PaymentMethod> paymentMethods) {
		this.paymentMethods = paymentMethods;
	}

	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ConfirmStatus getConfirmStatus() {
		return confirmStatus;
	}

	public void setConfirmStatus(ConfirmStatus confirmStatus) {
		this.confirmStatus = confirmStatus;
	}

	public Date getConfirmDate() {
		return confirmDate;
	}

	public void setConfirmDate(Date confirmDate) {
		this.confirmDate = confirmDate;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Boolean getIsInvoice() {
		return isInvoice;
	}

	public void setIsInvoice(Boolean isInvoice) {
		this.isInvoice = isInvoice;
	}

	public Date getInvoiceDate() {
		return invoiceDate;
	}

	public void setInvoiceDate(Date invoiceDate) {
		this.invoiceDate = invoiceDate;
	}

	public String getPayee() {
		return payee;
	}

	public void setPayee(String payee) {
		this.payee = payee;
	}

	public String getPayer() {
		return payer;
	}

	public void setPayer(String payer) {
		this.payer = payer;
	}

	public CommonUser getConfirmUser() {
		return confirmUser;
	}

	public void setConfirmUser(CommonUser confirmUser) {
		this.confirmUser = confirmUser;
	}

}
